//kechengxiangqin.js
var that;
const app=getApp();
var ipUrl=app.globalData.ipUrl;
var jing;
var wei;
var out;
Page({
  data: {
    active: 0,
    show: false,
    show1: false
  },
  onChange(event) {
    // event.detail 的值为当前选中项的索引
    that.setData({ active: event.detail });
  },
  //服务开启
  fuwu(){
    that.setData({ show: true });
  },
  //服务关闭
  onClose() {
    that.setData({ show: false });
    that.setData({ show1: false });
  },
  shouke(){
    wx.navigateTo({
      url: '../index/index'
    })
  },
  quanbukecheng(){
    wx.navigateTo({
      url: '../quanbukecheng/index?out='+out
    })
  },
  ditu(){
    console.log("jing1"+jing+"wei1"+wei)
    wx.navigateTo({
      url: '../ditu/index?jing='+jing+"&wei="+wei
    })
  },
  baoming(){
    that.setData({ show1: true });
  },
  fudao(){
    wx.navigateTo({
      url: '../index/index'
    })
  },
  onLoad: function (options) {
    that=this;
    that.setData({ 
      ipUrl: ipUrl
    });
    //  发送请求去查询服务保障
    wx.request({
      url: ipUrl+'/servicesafeguard/servicesafeguard/queryServicesafeguard',
      header: {
        'content-type': 'application/json' // 默认值
      },success(res){
        that.setData({
          serviceSafeList: res.data.data
        });
      },fail(e){
        console.log("服务保障连接controller错误")
      }
    })
    // 发起请求去查询课程详情
    wx.request({
      url: ipUrl+'/course/course/xiangQing?courseId='+options.id,
      header: {
        'content-type': 'application/json' // 默认值
      },
      success (res) {
        jing=res.data.position.geography.split(',')[0];
        wei=res.data.position.geography.split(',')[1];
        var a=res.data.thisWeek.split(',');
        out=JSON.stringify(res.data.outlines);
        var arr=res.data.outlines;
        if(arr.length>3){
          arr=arr.slice(0,3);
        }
        that.setData({
          arr:arr,
          changdu:arr.length,
          servletxiangqin:res.data,
          laoshi:res.data.teacherdetailsz[0].tname,
          jing:res.data.position.geography.split(',')[0],
          wei:res.data.position.geography.split(',')[1],
          shijian:a[a.length-2]
        });
      },fail(e){
        console.log("课程详情连接controller错误")
      }
    })

  },
})
